//
//  LYStatusCell.swift
//  微博
//
//  Created by liuerying on 16/5/24.
//  Copyright © 2016年 liuerying. All rights reserved.
//

import UIKit
import SnapKit
class LYStatusCell: UITableViewCell {

    //声明一个约束对象属性
    var toolBarTopCons: Constraint?
    
    var statuesModel: LYStatusViewModel? {
    
        didSet{
        
            statusOtiginaView.statutesModel = statuesModel
//            statusRetweetedView.statusViewModel=statuesModel
        
            StatusToolBar.statusViewModel = statuesModel
            //卸载约束对象
            toolBarTopCons?.uninstall()
            //判断有没有转发微博
            if  statuesModel?.status?.retweeted_status == nil {
            
                statusRetweetedView.statusViewModel = nil
                //隐藏转发视图
             statusRetweetedView.hidden = true
                //修改约束
                StatusToolBar.snp_updateConstraints(closure: { (make) in
                    
                 self.toolBarTopCons = make.top.equalTo(statusOtiginaView.snp_bottom).constraint
                    
                    
                })
                
            }else{
            
                statusRetweetedView.statusViewModel = statuesModel
                
                statusRetweetedView.hidden = false
                
                StatusToolBar.snp_updateConstraints(closure: { (make) in
                    
                  self.toolBarTopCons = make.top.equalTo(statusRetweetedView.snp_bottom).constraint
                    
                })
                
            }
        
            
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)

//        self.backgroundColor = randomColor()
    
        //设置cell的选中样式
        selectionStyle = .None

        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //设置界面
   private func setupUI(){
    
    contentView.addSubview(statusOtiginaView)
    contentView.addSubview(StatusToolBar)
    contentView.addSubview(statusRetweetedView)

    //原创微博添加约束
    statusOtiginaView.snp_makeConstraints { (make) in
        make.top.left.right.equalTo(self.contentView)
    }
    
    //给转发 底部条 添加约束
    StatusToolBar.snp_makeConstraints { (make) in
        
        make.left.right.equalTo(contentView)
       
        //给约束赋值--以便后期修改
       self.toolBarTopCons =  make.top.equalTo(statusRetweetedView.snp_bottom).constraint
     //设置高度
        make.height.equalTo(36)
        
        
    }
    
    //给转发微博视图添加约束
 
    statusRetweetedView.snp_makeConstraints { (make) in
       make.left.right.equalTo(contentView)
        make.top.equalTo(statusOtiginaView.snp_bottom)
       //测试用
//        make.height.equalTo(100)
    }
    
    //给cell的view底部添加约束
    contentView.snp_makeConstraints { (make) in
        make.top.left.right.equalTo(self)
        make.bottom.equalTo(StatusToolBar.snp_bottom)


    }
    
        
    }
    
    //微博原创视图
    private lazy var  statusOtiginaView : LYStatusOriginalView = LYStatusOriginalView()
    
    //微博底部tabbar
    private lazy var StatusToolBar: LYStatusToolBar = LYStatusToolBar()
    
    //转发微博的视图
    private lazy var statusRetweetedView: LYstatusRetweetedView = LYstatusRetweetedView()
    
}
